﻿using Microsoft.Extensions.Logging;
using StackExchange.Redis;

namespace Identification.Importer.Core.Setting
{
    public class SettingOption
    {
        protected ILogger Logger;

        private readonly ServiceSetting _setting;

        private readonly ConnectionMultiplexer _redis;

        protected SettingOption(ConnectionMultiplexer redis, ServiceSetting setting)
        {
            _redis = redis;
            _setting = setting;
        }

        public string SourceMongoServer { get; set; }

        public string SourceMongoDatabase { get; set; }

        public string SourceMongoCollection { get; set; }

        public int SourceQueryLimit { get; set; }

        public string SourceLatestObjectId
        {
            get
            {
                var objectId = _redis.GetDatabase(_setting.RedisDbIndex).StringGet($"{GetType().FullName}.ObjectId");
                Logger.LogInformation($"{GetType().FullName}.ObjectId is [{objectId}]");
                return objectId;
            }
            set
            {
                if (!string.IsNullOrWhiteSpace(value))
                {
                    Logger.LogInformation($"{GetType().FullName}.ObjectId was set to [{value}]");
                    _redis.GetDatabase(_setting.RedisDbIndex).StringSet($"{GetType().FullName}.ObjectId", value);
                }
            }
        }

        public string TargetMongoServer { get; set; }

        public string TargetMongoDatabase { get; set; }

        public string TargetMongoCollection { get; set; }

        public string IdentityWebServer { get; set; }

        public string IdentityWebSource { get; set; }

        public string ProductName { get; set; }
    }
}